﻿using System.Collections.Generic;
using MinistryManager.DataAccess.Entities;
using MinistryManager.DataAccess.Services.NHibernate;
using MinistryManager.DataAccess.Services.ServiceInterfaces;
using NHibernate.Criterion;

namespace MinistryManager.DataAccess.Services
{
    public class VolunteerService : IVolunteerService
    {
        private readonly IDataModel _dataModel;

        public VolunteerService() : this(NHibernateModel.GetInstance())
        {
            
        }

        public VolunteerService(IDataModel dataModel)
        {
            _dataModel = dataModel;
        }

        public Volunteer GetUserByUserNameAndPassword(string username, string password)
        {
            var conditions = new List<ICriterion>
            {
                Restrictions.Eq("Email", username),
                Restrictions.Eq("Password", password)
            };

            var results = _dataModel.GetByCriterion<Volunteer>(conditions);

            return results.Count == 1 ? results[0] : null;
        }
    }
}
